package com.xone.collaboration.service.impl.strategy;

import com.google.common.collect.Lists;
import com.xone.collaboration.dao.dataobject.LayerExample;
import com.xone.collaboration.dao.mapper.LayerMapper;
import com.xone.collaboration.service.OpStrategy;
import com.xone.collaboration.service.aonntation.Strategy;
import com.xone.collaboration.service.impl.process.OperationContext;
import com.xone.collaboration.service.vo.OperationResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Strategy("DELETE")
@Component
@Slf4j
public class DeleteOpStrategy implements OpStrategy {

    @Autowired
    private LayerMapper mapper;

    @Override
    public OperationResult operate(OperationContext context) {
        try{
            List<Integer> layerIds = Lists.newArrayList();
            context.getElements().forEach(element->{
                LayerExample example = new LayerExample();
                example.createCriteria().andLayerIdEqualTo(element.getLayerId());
                mapper.deleteByExample(example);
            });
        }catch (Exception e){
            log.error("delete layer error:",e);
            return OperationResult.of(false,e.getMessage());
        }
        return OperationResult.of(true,null);
    }
}
